﻿using JJYYCore;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class ExampleObjectPoolFactory : ObjectPoolResFactoryBase
{
    private List<ExampleCollectionRes> poolRes;

    public override IPoolRes Get(string id)
    {
        var containKey = poolRes.Any(res => res.ID == id);

        if (containKey)
        {
            var res = poolRes.FirstOrDefault(selection => selection.ID == id);
            var created = Object.Instantiate(res.gameObject);
            return created.GetComponent<ExampleCollectionRes>();
        }

        return null;
    }

    public ExampleObjectPoolFactory(List<GameObject> poolResNode){
        poolRes = new List<ExampleCollectionRes>();

        for (int i = 0; i < poolResNode.Count; i++)
        {
            var selection = poolResNode[i].GetComponent<ExampleCollectionRes>();
            if(selection)
                poolRes.Add(selection);

        }
    }
}
